package com.robot.mq.handler;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import entity.Sms;

/**
 * @author wuyunbin
 */
public class AliSmsHandler {

    public static void send(Sms sms) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4FofUMoUvsEthfqZLePj", "OzHISGBdWqSfzhmi7w9QSpJgGBcA04");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        String login = "login";
        String updatePassword = "updatePassword";
        String findPassword = "findPassword";
        String updatePhone = "updatePhone";
        String apply = "apply";

        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", sms.getPhone());
        request.putQueryParameter("SignName", "码上结");

        if (login.equals(sms.getFlag())) {
            request.putQueryParameter("TemplateCode", "SMS_186895214");
        } else if (updatePassword.equals(sms.getFlag())) {
            request.putQueryParameter("TemplateCode", "SMS_186895211");
        } else if (findPassword.equals(sms.getFlag())) {
            request.putQueryParameter("TemplateCode", "SMS_187745807");
        } else if (updatePhone.equals(sms.getFlag())) {
            request.putQueryParameter("TemplateCode", "SMS_187740894");
        } else if (apply.equals(sms.getFlag())) {
            request.putQueryParameter("TemplateCode", "SMS_187750851");
        } else {
            request.putQueryParameter("TemplateCode", "SMS_187755898");
        }


        request.putQueryParameter("TemplateParam", "{\"code\":\"" + sms.getCode() + "\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

}
